<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>用户管理-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, staff-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-body">
			<form id="staff_form" action="" method="post" class="layui-form layui-form-pane">
				<div class="layui-form-item">
					<label for="staff_name" class="layui-form-label">
                        <span class="we-red">*</span>姓名
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_name" name="name" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_code" class="layui-form-label">
                        <span class="we-red">*</span>工号
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_code" name="staffCode" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_code" class="layui-form-label">
                        企业微信账号
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="userid" name="userid" placeholder="用户激活后自动生成" readonly required="" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_mobile" class="layui-form-label">
                        电话
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_mobile" readonly placeholder="用户激活后自动绑定" name="mobile" required="" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_position" class="layui-form-label">
                       <span class="we-red">*</span> 职位
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_position" name="position" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_positionCode" class="layui-form-label">
                       <span class="we-red">*</span> 职位编号
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_positionCode" name="positionCode" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_department_code" class="layui-form-label">
                       <span class="we-red">*</span>部门编号
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_department_code" name="departmentCode" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_department_name" class="layui-form-label">
                       <span class="we-red">*</span>部门名称
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_department_name" name="departmentName" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_store_code" class="layui-form-label">
                       门店编号
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_store_code" name="storeCode" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_leader_code" class="layui-form-label">
                       所属长工号
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_leader_code" name="leaderCode" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_leader_name" class="layui-form-label">
                       所属长姓名
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="staff_leader_name" name="leaderName" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_gender" class="layui-form-label">
                       性别
                    </label>
					<div class="layui-input-inline">
						<select id="staff_gender" name="gender" class="valid">
							<option value="1">男</option>
							<option value="0">女</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label for="staff_visible" class="layui-form-label">
                       工作台权限
                    </label>
					<div class="layui-input-inline">
						<select id="staff_visible" name="visible" class="valid">
							<option value="0">否</option>
							<option value="1">是</option>
						</select>
					</div>
				</div>
				<!-- 用户状态 只有当当前操作是修改 且用户状态正常或者是禁用的时候 才显示 -->
				<div id="staff_status_div" style="display:none" class="layui-form-item">
					<label for="staff_status" class="layui-form-label">
                        用户状态
                    </label>
					<div class="layui-input-inline">
						<select id="staff_status_select" name="status" class="valid">
							<option value="1">正常</option>
							<option value="2">禁用</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
				</div>
			</form>
		</div>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/admin.js" charset="utf-8"></script>
		<script src="../../publicjs/jquery-1.8.0.min.js" charset="utf-8"></script>
		<script src="../../publicjs/smallkingutil.js" charset="utf-8"></script>
		<script type="text/javascript">
			layui.use(['form', 'layer'], function() {
				var form = layui.form,
					layer = layui.layer;
				// 先判断当前的操作是新增还是修改
				var staffId = commonUtil.getRequestParam("staffId");
				if(staffId) {
					// 请求后台得到当前修改的用户数据，将其显示在表单里
					var ajaxParam = {
						url: commonUtil.domain() + '/admin/wxwork/staff/detail',
						data: {
							staffId: staffId
						}
					}
					ajaxUtil.post(ajaxParam, function(data) {
						formUtil.setForm($('#staff_form'), data.data);
						form.render("select");
						var status = data.data.status;
						window.staff = data.data;
						if(status == 1 || status == 2) {
							$("#staff_status_div").show();
							$("#staff_status_select").attr("disabled", false);
						} else {
							$("#staff_status_select").attr("name", "xxx");
						}
					});
				}
				// 监听表单提交
				form.on('submit(add)', function(data) {
					var data = data.field;
					var url, msg;
					// 有staffId就是修改，没有staffId就是新增
					if(staffId) {
						url = commonUtil.domain() + "/admin/wxwork/staff/update";
						msg = "修改员工";
						data.staffId = staffId;
						// 如果员工之前是离职状态 不允许修改
						if(window.staff.status == 3) {
							layer.alert("用户已离职，不允许修改。");
							return false;
						}
					} else {
						url = commonUtil.domain() + "/admin/wxwork/staff/insert";
						msg = "新增员工";
					}
					// 验证员工号是否合格
					if(data.staffCode.length != 6 || isNaN(data.staffCode)) {
						layer.alert("员工号格式错误。");
						return false;
					}
					var ajaxParam = {
						url: url,
						data: data
					}
					// 发送ajax 提交表单数据
					ajaxUtil.post(ajaxParam, function(data) {
						if(data.code == 200) {
							layer.alert(msg + "成功", {
								icon: 6
							}, function() {
								// 刷新父级的用户表格
								var parentHtml = window.parent;
								parentHtml.staffTable.refresh();
								//关闭当前frame
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						} else {
							layer.alert(data.msg);
						}
					});
					return false;
				});

			});
		</script>
		<script>
			$(function() {
				commonUtil.setMaxLength(40);
			})
		</script>
	</body>

</html>